<template>
	<view class="community">
		<view class="head_bg">
			<view class="cu-bar search">
				<view class="search-form bg-white" style="border-radius:50rpx;">
					<text class="cuIcon-search"></text>
					<input type="text" placeholder="" confirm-type="search" @input="getinputvalue"></input>
					 <view @tap="search" class="text-right margin-right-sm text-lg">搜索</view>
				</view>
			</view>
		</view>
		<view class="big_box" style="height: auto;">
			<view class="big_box_inner" style="margin-bottom:20rpx;"  v-for="(info,index) in list" :key="index" @tap="todetail(info)">
				<view class="big_inner_one">
					<view class="plot_inner">
						<view class="plot_inner_left">{{info.residential_quarters_name}}</view>
						<view class="plot_inner_left">总电费：<text class="plot_inner_right">{{info.electricity_charge_entry}}元</text>
						   <image class="plot_inner_img" src="../../../common/img/zhankai.png" mode=""></image>
					    </view>
					</view>
				</view>
			</view>
		</view>
		<view style="height:100rpx;"></view>
		<view v-if="list.length==0" class="margin-top-lg text-center">
			<image src='../../../common/img/no_data.png' style="width:275rpx;height:312rpx;"></image>
		</view>
		<view v-if="list.length>0" class="text-black text-df text-center bg-white padding-sm padding-left-lg be-gray">
			{{loadingTxt}} 共({{list.length}}条记录)
		</view>
	</view>
</template>

<script>
	let page=1,timer=null
	export default {
		data() {
			return {
				list:[],
				loadingTxt:'加载更多',
				inputval:"",
			}
		},
		onShow() {
			page=1;
			this.gatdata();
		},
		methods: {
			getinputvalue: function(event) {
				this.inputval = event.target.value  
			}, 
			search(){
				page=1;
				this.gatdata();
				this.inputval=''
			},
			todetail(item){
				uni.navigateTo({
					url: '../electricity/electricity?item='+JSON.stringify(item)
				})
			},
			gatdata(){
				let that=this;
				that.http.tokenreq({
					url: 'electricitychargeentry/v1/village',
					data:{"pageindex":page,
					      "village":this.inputval
					}
				}).then((res) => {
					console.log("res="+JSON.stringify(res));
					let e=res.data;
					if(e.code==0 && e.success){
						let list=e.rows;
						that.list=list;
						page++;
					}
				})
			},
			getmorelist(){
				this.loadingTxt='加载中'
				let that=this;
				that.http.tokenreq({
					url: 'electricitychargeentry/v1/village',
					data:{"pageindex":page,
					      "village":this.inputval
					}
				}).then((res) => {
					uni.hideLoading();
					let e=res.data;
					if(e.code==0 && e.success){
						if(e.rows.length==0){
							that.loadingTxt="已经加载全部";
							return;
						}
						that.list=that.list.concat(e.rows);
						page++
					}
				})
			},
			onReachBottom() {
				//阻止重复加载
				if(timer !== null){
					clearTimeout(timer)
				}
				timer=setTimeout(()=>this.getmorelist(),500)
				// this.getMoreNews()
			},
		}
	}
</script>
<style>
	page{
		background-color: #FFFFFF;
	}
</style>
